<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>检查数据类型</title>
  </head>
  <body>
    <script>
      /*
        1. typeof
          可以检测
            number string boolean undefined symbol bigint function

          不可以检测
            null
            object
            array

        2. A instanceof B
          简单理解：检测A是否是B的实例（B是否是A的构造函数）
          真正理解：检测A的隐式原型是否在B的显示原型上，在返回true，不在返回false

          使用场景：检测A是否是B的实例(只用于检测引用类型)
                    xxx instanceof Promise

        3. Object.prototype.toString.call(target).slice(8, -1)

          可以检测所有数据类型

        4. ===
        
          用来判断数据的值和类型都要相等

        5. Array.isArray() 
      */
      console.log(typeof 123);
      console.log(typeof "123");
      console.log(typeof true);
      console.log(typeof null); // object
      console.log(typeof undefined);
      console.log(typeof Symbol());
      console.log(typeof 123n);
      console.log(typeof {}); // object
      console.log(typeof []); // object
      console.log(typeof function () {});

      console.log({} instanceof Object); // true
      console.log([] instanceof Array); // true
      console.log([] instanceof Object); // true

      console.log(Object.prototype.toString.call(123).slice(8, -1));
      console.log(Object.prototype.toString.call("123").slice(8, -1));
      console.log(Object.prototype.toString.call(true).slice(8, -1));
      console.log(Object.prototype.toString.call(null).slice(8, -1));
      console.log(Object.prototype.toString.call(undefined).slice(8, -1));
      console.log(Object.prototype.toString.call(Symbol()).slice(8, -1));
      console.log(Object.prototype.toString.call(123n).slice(8, -1));
      console.log(Object.prototype.toString.call({}).slice(8, -1));
      console.log(Object.prototype.toString.call([]).slice(8, -1));
      console.log(Object.prototype.toString.call(function () {}).slice(8, -1));
      console.log(
        Object.prototype.toString.call(Promise.resolve()).slice(8, -1)
      );
      console.log(Object.prototype.toString.call(new Date()).slice(8, -1));
      console.log(Object.prototype.toString.call(/\.js$/).slice(8, -1));
    </script>
  </body>
</html>
